package com.suep.data_analysis.controller;

import com.suep.data_analysis.dto.ArmamentDto;
import com.suep.data_analysis.service.ArmamentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@AllArgsConstructor
@RestController
@RequestMapping("api/armaments")
public class ArmamentController {
    private final ArmamentService armamentService;

    @Operation(
            summary = "获取音擎列表",
            description = "查询所有音擎的基本信息",
            responses = {
                    @ApiResponse(responseCode = "200", description = "成功获取音擎列表",
                            content = @Content(mediaType = "application/json",
                                    schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = ArmamentDto.class)))
            }
    )
    @GetMapping
    public ResponseEntity<List<ArmamentDto>> getAllArmaments() {
        List<ArmamentDto> armaments = armamentService.getAllArmaments();
        return ResponseEntity.ok(armaments);
    }

    @Operation(
            summary = "根据ID查询音擎详情",
            description = "查询指定音擎的完整信息",
            parameters = {
                    @Parameter(name = "armamentId", description = "音擎ID", required = true,
                            examples = @ExampleObject(value = "1342", description = "青溟笼舍音擎"))
            },
            responses = {
                    @ApiResponse(responseCode = "200", description = "成功获取音擎详情",
                            content = @Content(mediaType = "application/json",
                                    schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = ArmamentDto.class))),
                    @ApiResponse(responseCode = "404", description = "音擎不存在", content = @Content)
            }
    )
    @GetMapping("/{armamentId}")
    public ResponseEntity<ArmamentDto> getArmamentById(@PathVariable String armamentId) {
        ArmamentDto armament = armamentService.getArmamentById(armamentId);
        if (armament == null) {
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(armament);
    }

    @Operation(
            summary = "搜索音擎",
            description = "根据关键词搜索音擎（支持名称、类别、效果搜索）",
            parameters = {
                    @Parameter(name = "keyword", description = "搜索关键词", required = true,
                            examples = @ExampleObject(value = "青溟", description = "搜索包含'青溟'的音擎"))
            },
            responses = {
                    @ApiResponse(responseCode = "200", description = "成功获取搜索结果",
                            content = @Content(mediaType = "application/json",
                                    schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = ArmamentDto.class)))
            }
    )
    @GetMapping("/search")
    public ResponseEntity<List<ArmamentDto>> searchArmaments(@RequestParam String keyword) {
        List<ArmamentDto> result = armamentService.searchArmaments(keyword);
        return ResponseEntity.ok(result);
    }
}